package com.zhihuichongcheng.application.glide;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.DiskCache;
import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper;
import com.bumptech.glide.module.GlideModule;
import com.zhihuichongcheng.application.constant.Constants;

import java.io.File;

/**
 * Created by 3water on 2016/10/25.
 */

public class GlideConfiguration implements GlideModule {
    @Override
    public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File cacheLocation = new File(Constants.Const_Cache_Dir);
                if (!cacheLocation.exists()) {
                    cacheLocation.mkdirs();
                }
                return DiskLruCacheWrapper.get(cacheLocation, 10 * 1024 * 1024);
            }
        });
    }
    @Override
    public void registerComponents(Context context, Glide glide) {
    }
}
